package com.zjhs.affluence.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zjhs.affluence.entity.*;
import com.zjhs.affluence.mapper. ${ClassName}Mapper;
import com.zjhs.affluence.service.*;
import com.zjhs.base.mybatisplus.PageQuery;
import com.zjhs.base.mybatisplus.PageQueryUtil;
import com.zjhs.common.dto.Result;
import com.zjhs.usercenter.service.IDictCodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;

/**
 * ${table.comment}
 *
 */
@Slf4j
@Service
public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}> implements I${ClassName}Service {


	@Resource
	private ${ClassName}Mapper ${className}Mapper;
	@Resource
	private IDictCodeService iDictCodeService;


	@Override
	public IPage<${ClassName}> getList(PageQuery pageQuery) {
		IPage<${ClassName}> pageList = new Page<>(pageQuery.getPageNo(), pageQuery.getPageSize());
		QueryWrapper<${ClassName}> queryWrapper = PageQueryUtil.getQueryWrapper(pageQuery);
		pageList = this.page(pageList, queryWrapper);
		return pageList;
	}

	@Override
	public Result list(List<Long> ids) {
		List<${ClassName}> list = query().in("ID",ids).list();
		return Result.success(list);
	}

	@Override
	public 	${ClassName}  get(Long id) {
		${ClassName} ${className} = ${className}Mapper.selectById(id);
		return ${className};
	}

	@Override
	public Result insert(${ClassName} ${className}) {

		${ClassName} ${className} = new ${ClassName}();
		<#list table.columns  as column>
		<#if column_has_next>
		${className}.set${column.columnName3}(${column.defaultValue});   //${column.columnComment}
		<#else>
		${className}.set${column.columnName3}(${column.defaultValue});    //${column.columnComment}
		</#if>
		</#list>

		${className}Mapper.insert(${className});
		return Result.success(${className});
	}

	@Override
	public Result update(${ClassName} ${className}) {
		${className}Mapper.updateById(${className});
		return Result.success(${className});
	}

	@Override
	public Result deleteById(Long id) {
        ${className}Mapper.deleteById(id);
        return Result.success();
	}



}
